﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using simpleHotel.Business;

namespace simpleHotel.Web
{
    public partial class BookingPaid : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!IsPostBack)
            //{
                PaidResult();
            ////}
        }

        private void PaidResult()
        {
            try
            {

                string SECURE_SECRET = "A3EFDFABA8653DF2342E8DAC29B51AF0";
                string hashvalidateResult = "";
                // Khoi tao lop thu vien
                VPCRequest conn = new VPCRequest("http://onepay.vn");
                conn.SetSecureSecret(SECURE_SECRET);
                // Xu ly tham so tra ve va kiem tra chuoi du lieu ma hoa
                hashvalidateResult = conn.Process3PartyResponse(Page.Request.QueryString);


                // Lay gia tri tham so tra ve tu cong thanh toan
                String vpc_TxnResponseCode = conn.GetResultField("vpc_TxnResponseCode", "Unknown");
                string amount = conn.GetResultField("vpc_Amount", "Unknown");
                string localed = conn.GetResultField("vpc_Locale", "Unknown");
                string command = conn.GetResultField("vpc_Command", "Unknown");
                string version = conn.GetResultField("vpc_Version", "Unknown");
                string cardBin = conn.GetResultField("vpc_Card", "Unknown");
                string orderInfo = conn.GetResultField("vpc_OrderInfo", "Unknown");
                string merchantID = conn.GetResultField("vpc_Merchant", "Unknown");
                string authorizeID = conn.GetResultField("vpc_AuthorizeId", "Unknown");
                string merchTxnRef = conn.GetResultField("vpc_MerchTxnRef", "Unknown");
                string transactionNo = conn.GetResultField("vpc_TransactionNo", "Unknown");
                string txnResponseCode = vpc_TxnResponseCode;
                string message = conn.GetResultField("vpc_Message", "Unknown");

                if (hashvalidateResult == "CORRECTED" && txnResponseCode.Trim() == "0")
                {
                    BookingBLL obj = new BookingBLL();

                    //if (Session["STATUSTRANSFER"] != null)
                    //    obj.UpdateBookingInfo(Session["STATUSTRANSFER"]+"", 1);

                    lblResult.Text = "Giao dịch thành công";

                }
                else if (hashvalidateResult == "INVALIDATED" && txnResponseCode.Trim() == "0")
                {
                    lblResult.Text = "Giao dịch đang chờ";
                }
                else
                {
                    lblResult.Text = "Giao dịch thất bại";
                }
                //vpc_Version.Text = version;
                lblAmount.Text = amount;
                //vpc_Command.Text = command;
                //vpc_MerchantID.Text = merchantID;
                //vpc_MerchantRef.Text = merchTxnRef;
                //vpc_OderInfor.Text = orderInfo;
                //vpc_ResponseCode.Text = txnResponseCode;
                //vpc_Command.Text = command;
                //vpc_TransactionNo.Text = transactionNo;
                //hashvalidate.Text = hashvalidateResult;
                //vpc_Message.Text = message;
            }
            catch (Exception)
            {
                pnl.Visible = false;
                lblError.Text = "No transaction done";
            }
            
           
        }

    }
}